#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <stdlib.h>

#define st_size 10

struct Stack_t
{
    int count;
    double data[st_size];
};

typedef struct Stack_t Stack_t;


int stack_construct ( Stack_t* st );

int stack_destruct ( Stack_t* st );

int stack_OK ( const Stack_t* st );

int stack_push ( Stack_t* st, double val );

double stack_pop ( Stack_t* st );

int stack_full ( Stack_t* st );

int stack_empty ( Stack_t* st );

int stack_dump ( Stack_t* st );


int main()
{
    return 0;
}

int stack_construct ( Stack_t* st )
{
    int i = 0;
    for ( i = 0; i < st_size; i++ )
    {
        st->data[i] = 0;
    }
    st->count = 0;
}

int stack_destruct ( Stack_t* st )
{
    int i = 0;
    for ( i = 0; i < st_size; i++ )
    {
        st->data[i] = 0xBADF00D;
    }
    st->count = 0;
}

int stack_OK ( const Stack_t* st )
{
    return ( st && 0 <= st->count && st->count <= st_size );
}

int stack_push ( Stack_t* st, double val )
{
    //int count1 = st->count;
    if ( !stack_OK ( st ) )
    {
        stack_dump ( st );
        assert(!" stack_push " );
    }
    else
    {
        st->data[st->count] = val;
        (st->count)++;
    }
    if ( !stack_OK ( st ) )
    {
        stack_dump ( st);
        assert(!" stack_push " );
    }
}

double stack_pop ( Stack_t* st )
{
    double pop = 0;
    if ( !(st && 0 <= st->count-1 && st->count <= st_size)  )
    {
        stack_dump ( st );
        assert(!" stack_pop __LINE__" );
    }
    else
    {
        (st->count)--;
        return st->data[st->count];
    }
    if ( !stack_OK ( st ) )
    {
        stack_dump ( st );
        assert(!" stack_pop __LINE__" );
    }
}

int stack_full ( Stack_t* st )
{
    if ( st->count = st_size-1)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

int stack_empty ( Stack_t* st )
{
    if ( st->count == 0 )
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

int stack_dump ( Stack_t* st )
{
    printf ( "Stack\n" );
    if (stack_OK ( st ) )
    {
        printf ( "ok\n" );
    }
    else
    {
        printf ( "BAD\n");
    }
    printf ( "count = %i\n", st->count );
    printf ( "size of stack = %i\n", st_size );
    int i = 0;
    for (i = 0; i < st_size; i++)
    {
        if ( i < st->count )
        {
            printf ( "data[%i] = %lf *\n", i, st->data[i] );
        }
        else
        {
            printf ( "data[%i] = %lf\n", i, st->data[i] );
        }
    }
}
